Copyright: Copyright 1996 Silicon Commander Games


TColorPalette Component

Properties	Methods

Unit

ColorPalette

Description

The TColorPalette component encapsulates a 256 color Windows logical palette.  When it is first created, the TColorPalette takes the first and last 10 colors from the system palette, and fills the remaining 235 with shades of gray.  The first and last 10 palette entries are reserved by Windows and should not be modified.

You can load the palette entries of an existing image  at design time by using the object inspector to assign a TImage component to the ImagePalette property.  The reference to the TImage is not maintained, but the Timage’s palette entries are copied into the TColorPalette.

The PaletteEntries property allows you to visually manipulate the palette entries at design time.  The associated property editor supports saving and loading palette data from files, using the same palette file format (PAL) that is used by PaintShop Pro.

To access palette entries at run time, use the indexed PaletteEntry property which returns a TPaletteEntry.

A number of custom components, such as TColorPanel and TDIBDrawingSurface, can link to a single TColorPalette component.


Properties

BadEntries	IdentityPalette	ImagePalette

PalEntryFlag	Palette	PaletteEntries

PaletteEntry


Methods

Assign	Refresh


Assign Method

Applies To

TColorPalette

Declaration

procedure Assign( source: TPersistent ); override;

Description

The Assign procedure copies the entries of one TColorPalette into another.  After Assign, the logical palette is re-created using the new palette entries.


Refresh Method

Applies To

TColorPalette

Declaration

procedure Refresh;

Description

The Refresh methods causes the logical palette to be re-created, using the current palette entries.  Use this method to re-create the palette after you’ve modified entries at run time using the PaletteEntry property.


Palette Property

Applies To

TColorPalette

Declaration

property Palette: HPALETTE;

Description

The Palette property returns the logical palette handle associated with the component.


PaletteEntry Property

Applies To

TColorPalette

Declaration

property PaletteEntry[n: byte]: TPaletteEntry;

Description

The PaletteEntry property exposes the palette entries at run time.  You can view or modify any palette entry in the 256 color palette.  After you are finished modifying palette entries, call the Refresh method to re-create the logical palette.


BadEntries Property

Applies To

TColorPalette

Declaration

property BadEntries: TStrings

Description

The BadEntries property is provided as a design time tool to aid in the creation of an identity palette.  If the IdentityPalette property is False, one or more palette entries have the same color value as one of the first 10 system palette entries.  This will prevent an identity palette from being created, and can impact graphics performance when using DIBs.  You can look at the BadEntries values to target the problem palette entries, then use the PaletteEntries property editor to correct the values.


PaletteEntries Property

Applies To

TColorPalette

Declaration

property PaletteEntries: TStrings

Description

The PaletteEntries property is a TStrings that actually stores the physical palette entry data.  A property editor is provided that allows you to visually modify the palette at design-time.  This editor supports the saving and loading of palette data to files, using the PAL file format made popular by PaintShop Pro.  If you need to access the palette entries at run time, you should not use this property, but rather the PaletteEntry indexed property that allows you to access any of the 256 TPaletteEntry records that make up the palette.


ImagePalette Property

Applies To

TColorPalette

Declaration

property ImagePalette: TImage;

Description

When you assign an existing TImage component to this property, the palette entries of the associated bitmap are copied into the TColorPalette.  The reference to the TImage is not maintained, so the TImage may be deleted from the form after the data copy is completed.  The TColorPalette stores its own palette entry information, so any lasting link to the TImage is not required.  The palette is automatically re-created after a value is assigned to this property.


IdentityPalette Property

Applies To

TColorPalette

Declaration

property IdentityPalette: boolean;

Description

This property is a design-time aid that will indicate whether an identity palette was achieved.  An identity palette is a palette whose first and last 10 entries match the system palette, and whose middle 236 entries do not duplicate any of the first 10 system palette entries.  Creating an identity palette allows Windows to bypass lengthy palette mapping operations, and results in better graphics performance.  If this property is False, use the BadEntries property to zero in on the problem entries, then use the PaletteEntries property editor to correct them.


PalEntryFlag Property

Applies To

TColorPalette

Declaration

property PalEntryFlag: TPalEntryFlag

Description

This property controls the flag values of the middle 236 TPaletteEntries in the palette.  The possible values are pcNoCollapse, and pcReserved.  In most cases you should just leave the property at its default setting of pcNoCollapse, as pcReserved can cause a window to render incorrectly when it is in the background.  PcReserved will, however, make it possible to create an identity palette even if one or more of the middle 236 palette entries duplicate one of the first 10 system palette entries.